package cate.game.role.res.farm;

import cate.common.table.res.farm.row.FarmSeedLevelRow;
import cate.common.util.GameResult;
import cate.game.res.MixRes;
import cate.game.res.MixResItem;
import cate.game.role.Role;
import easy.java.dev.note.NoteField;

public class FarmSeed {
    @NoteField("种子等级")
    public int seedLevel;

    @NoteField("种子类型")
    public byte seedType;

    public FarmSeed() {

    }

    public FarmSeed(byte seedType, int seedLevel) {
        this.seedType = seedType;
        this.seedLevel = seedLevel;
    }

    public GameResult<Void> levelUp(Role role) {
        GameResult<Void> r = new GameResult<>();
        FarmSeedLevelRow nextLevelRow = role.getGame().table.farm.seedLevel.getNextLevelRow(seedType, seedLevel);
        if (nextLevelRow == null) {
            return r.fail("种子已经升到满级啦");
        }
        GameResult<MixResItem> consumeRes = new MixRes(nextLevelRow.levelConsumeItemStr).consume(role);
        if (!consumeRes.ok()) {
            consumeRes = new MixRes(nextLevelRow.levelConsumeStr).consume(role);
            if (!consumeRes.ok()) {
                return r.fail(consumeRes);
            }
        }
        this.seedLevel ++;
        return r;
    }

    public void reset() {
        this.seedLevel = 1;
    }
}
